function [X_norm, out1, out2] = featureNormalize(X, type)
% [X_norm, xmin, xmax] = featureNormalize(X, 'range') (default)
% [X_norm, mu, sigma]  = featureNormalize(X, 'mean') 

    if nargin < 2; type = 'range'; end
    
    switch type
        case 'range'
            [X_norm, out1, out2] = rangeMethod(X);
        case 'mean'
            [X_norm, out1, out2] = meanMethod(X);
        otherwise
            error('error');
    end

end

function [X_norm, mu, sigma]  = meanMethod(X) 
    mu = mean(X, 1);
    sigma = std(X, 1);
    X_norm = (X - mu) ./ (sigma + eps); 
end

function [X_norm, xmin, xmax] = rangeMethod(X)
    xmin = min(X, [], 1);
    xmax = max(X, [], 1);
    X_norm = (X - xmin) ./ (xmax - xmin + eps);
end

